<?php
/**
 * Zead
 *
 * LICENSE	
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/bsd-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to eu@marcelomx.com so we can send you a copy immediately.
 *
 * @category   Zead
 * @author     Marcelo Rodrigues Gonzaga <eu@marcelomx.com>
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga
 * @link       http://code.google.com/p/zead 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License
 *
 **/


/** @see Zead_Html_Helper_Abstract **/
require_once 'Zead/Html/Helper/Abstract.php';

/**
 * @category   Zead
 * @package    Zead_Html
 * @subpackage Zead_Html_Helper
 * @copyright  Copyright (c) 2008 Marcelo Rodrigues Gonzaga 
 * @license    http://www.opensource.org/licenses/bsd-license.php     New BSD License  
 */
class Zead_Html_Helper_Widgets extends Zead_Html_Helper_Abstract 
{
	/**
	 * Executando o helper. Como os atributos podem ser variados e ser uma ordem
	 * de obrigatoriedade e com diferentes funções assumidas, então os atributos
	 * podem ser passados em qualquer ordem.
	 *
	 * @param array $attributes
	 */
	public function widgets($contentsList, $tokenId = null) 
	{
		$widgetsBlock = $this->getWidgetBlock();
		
		// Creating the print form section
		$printWidgetBlock = $widgetsBlock->appendChild($this->html->createElement('div'));
		$printWidgetBlock->addClassName('printWidget');
		
		// Creating the form print
		$form = $printWidgetBlock->appendChild($this->html->createElement('form'));
		$hidden = $form->appendChild($this->html->createElement('input'));
		$hidden->setAttribute('type', 'hidden');
		$hidden->setAttribute('name', 'id');
		$hidden->setAttribute('value', $tokenId);
		
		$hidden = $form->appendChild($this->html->createElement('input'));
		$hidden->setAttribute('type', 'hidden');
		$hidden->setAttribute('name', 'action');
		$hidden->setAttribute('value', 'print');
		
		$label = $form->appendChild($this->html->createElement('label'));
		$label->setAttribute('for', 'content_id');
		$label->nodeValue = 'Print version: ';
		
		$select = $label->appendChild($this->html->createElement('select'));
		$select->setAttribute('name', 'content_id');
		$select->setAttribute('id', 'content_id');
		
		foreach ($contentsList as $content) {
			$option = $select->appendChild($this->html->createElement('option'));
			$option->setAttribute('value', $content->id);
			$option->nodeValue = $content->getTitle();
		}
		$button = $form->appendChild($this->html->createElement('button'));
		$button->nodeValue = 'Go!';
		
		/** @see Zend_Form **/
		//require_once 'Zend/Form.php';
		//$form = new Zend_Form();
	}
	
	/**
	 * Returns the widget block
	 *
	 * @return DOMElement
	 */
	protected function getWidgetBlock()
	{
		// Criando o elemento, ser for necessário
		if (!($widgetBlock = $this->html->getElementById('widgets'))) {
			$widgetBlock = $this->html->body()->appendChild($this->html->createElement('div'));
			$widgetBlock->setAttribute('id', 'widgets');
		}
		
		return $widgetBlock;		
	}
}

